package chap9;

import stone.StoneException;
import stone.ast.ClassBody;
import stone.ast.ClassStmnt;
import chap6.Environment;

public class ClassInfo {

    protected ClassStmnt definition;
    protected Environment env;
    protected ClassInfo superClass;

    public ClassInfo(ClassStmnt cs, Environment env) {
        super();
        this.definition = cs;
        this.env = env;

        Object obj = env.get(cs.superClass());
        if (obj == null) {
            superClass = null;
        } else if (obj instanceof ClassInfo) {
            superClass = (ClassInfo) obj;
        } else {
            throw new StoneException("unkown super class:" + cs.superClass());
        }

    }

    public String name() {
        return definition.name();
    }

    public ClassInfo superClass() {
        return superClass;
    }

    public ClassBody classBody() {
        return definition.body();
    }

    public Environment environment() {
        return env;
    }

    @Override
    public String toString() {
        return "<class " + name() + "]";
    }
}
